using UnityEngine;
using Voodoo.Sauce.Common.Utils;
using Voodoo.Sauce.Internal.CrossPromo.Mercury;
using Voodoo.Sauce.Tools.AccessButton;
using Voodoo.Sauce.Tools.PerformanceDisplay;

namespace Voodoo.Sauce.Debugger
{
	public class OptionsDebugScreen : Screen
	{
		private void OnEnable()
		{
			ClearDisplay();
			Toggle("Enable Access Button", AccessProcess.HasAccess(), ToggleAccessButton);
			Toggle("Enable Performance Display", PerformanceDisplayManager.IsEnabled, TogglePerformanceDisplay);
			if (PlatformUtils.UNITY_EDITOR || !Debug.isDebugBuild)
			{
				Label(GetFakeAdsMessage());
			}
			Toggle("Enable Cross Promo/Backup FS Test mode", MercuryTestModeManager.Instance.IsTestModeEnabled(), ToggleMercuryTestMode);
			Button("Delete PlayerPrefs", DeletePlayerPrefs);
		}

		private string GetFakeAdsMessage()
		{
			string result = "";
			if (PlatformUtils.UNITY_EDITOR)
			{
				result = "The fake ads can not be disabled in the in-editor mode.";
			}
			else if (!Debug.isDebugBuild)
			{
				result = "The fake ads can be enabled on development mode only.";
			}
			return result;
		}

		private void ToggleAccessButton(bool value)
		{
			AccessProcess.SetAccess(value);
		}

		private void TogglePerformanceDisplay(bool value)
		{
			PerformanceDisplayManager.IsEnabled = value;
		}

		private void ToggleMercuryTestMode(bool value)
		{
			MercuryTestModeManager.Instance.SetTestMode(value);
		}

		private void DeletePlayerPrefs()
		{
			Debugger.DisplayPopup(new DebuggerPopupConfig
			{
				message = "Are you sure you want to delete local PlayerPrefs? This action cannot be undone.",
				confirmCallback = NintendoPlayerPrefs.DeleteAll
			});
		}
	}
}
